﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OTS.BLL;

public partial class Contract_Contract : INTPage
{
    ContractBuildBLL build = new ContractBuildBLL();
    ContractDAO comm = new ContractDAO();
    ContractModel model = new ContractModel();
    CommonMethod comHelp = new CommonMethod();

    #region 
    private string _contracttable;
    public string contracttable
     {
         get { return _contracttable; }
        set { _contracttable = value; }
     }
    public string getContract()
    {
        return contracttable;
    }
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        CommonMethod.IsTimeOutUserCode(this, CommonModel.errorTimeOutUrl1);
        if (!IsPostBack)
        {   // 页面权限
            comHelp.GetRight(this, new string[] { Session["UserCode"].ToString(), Session["CoCode"].ToString(), 
                "contract" }, null, new string[] { "cmdNew", "cmdDataUpdateFromDB", "cmdDelete" }, new int[] { }, CommonModel.loginOut1);

            InitBind(Session["UserCode"].ToString());
            txtDateFrom.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
            txtDateTo.Value = System.DateTime.Now.ToString("yyyy-MM-dd");
            //txtContractNo.Value = System.DateTime.Now.ToString("hh:mm:ss");
            MoreQueryDdlBind();
        }
        CommonMethod.regAlertMessageScript(updcontract, "MoreQueryOnload();", this);
        lblMessage.Text = "";
    }

    private void InitBind(string userCode)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        //CoDep
        CoDepBind(userCode);
        //绑定合同浏览组
        contractGroupBind(userCode, 0);

        ContractNoRegulationBind();
    }

    // CoDep
    protected void ddlCoDep_SelectedIndexChanged(object sender, EventArgs e)
    {
        CommonMethod.IsTimeOutUserCode(this, CommonModel.errorTimeOutUrl1);
        contractGroupBind(Session["UserCode"].ToString(), 0);
        QueryNew();
    }
    // 根据合同组绑定角色组
    protected void ddlcontractGroup_ServerChange(object sender, EventArgs e)
    {
        //CommonMethod.IsTimeOutUserCode(this, CommonModel.errorTimeOutUrl1);
        //if (ddlcontractGroup.SelectedValue.Equals("-1"))
        //{
        //    //contractGroupRolesGroupBind(Session["UserCode"].ToString(), ddlcontractGroup.SelectedItem.Value.ToString());
        //    model.contractGroup = ddlcontractGroup.SelectedValue;
        //    model.ContractNoMain = "";
        //    model.pageIndex = 0;
        //    model.pageNextIndex = 1;
        //    model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        //    lblPageIndex.Text = "1";
        //    contractBind(model);
        //}
        //ChanageClick();
        QueryNew();
    }
    protected void QueryNew()
    {
        if (ddlcontractGroup.SelectedValue.Equals("-1"))
        {
            cmdSearch.Enabled = false;
            queryMore.Disabled = true;
            cmdNew.Enabled = false;
            cmdQueryMore.Enabled = false;
        }
        else
        {
            cmdSearch.Enabled = true;
            queryMore.Disabled = false;
            cmdQueryMore.Enabled = true;
            cmdNew.Enabled = true;
        }
    }
   
    // 绑定合同号规则
    protected void ContractNoRegulationBind()
    {
        DataTable[] dt = comm.GetContractNoRegulation();
        if (dt != null && dt.Length > 1 && dt[0].Rows.Count > 0)
        {
            ddlCNRSegment.DataSource = dt[0];
            ddlCNRSegment.DataValueField = "CNRSegment";
            ddlCNRSegment.DataTextField = "CNRSegment";
            ddlCNRSegment.DataBind();

            Session["dtCNRCoDe"] = dt[1];
            ContractNoRegulationCoDeBind();
        }
        else
        {
            ddlCNRSegment.Items.Clear();
            ddlCNRCoDe.Items.Clear();
        }
        ListItem item = new ListItem("请选择(Select Please)", "-1");
        ddlCNRSegment.Items.Add(item);
    }
    // 
    protected void ContractNoRegulationCoDeBind()
    {
        if (Session["dtCNRCoDe"] != null)
        {
            DataTable dt = (DataTable)Session["dtCNRCoDe"];
            DataRow[] row = dt.Select("CNRSegment='" + ddlCNRSegment.SelectedItem.Text + "'");
            ddlCNRCoDe.Items.Clear();
            foreach (DataRow r in row)
            {
                ddlCNRCoDe.Items.Add(new ListItem(r["CNRCoDe"].ToString(), r["CNRCoDe"].ToString()));
            }
            ListItem item = new ListItem("请选择(Select Please)", "-1");
            ddlCNRCoDe.Items.Insert(0, item);
            ddlCNRCoDe.SelectedIndex = 0;
        }
        else { ContractNoRegulationBind(); }
    }

    protected void ddlCNRSegment_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!ddlCNRSegment.SelectedValue.Equals("-1"))
        { ContractNoRegulationCoDeBind(); }
        else { ddlCNRCoDe.Items.Clear(); }
        //ChanageClick();
        QueryNew();
    }
    protected void ddlCNRCoDe_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if (Session["dtCNRCoDe"] != null)
        //{
        //    DataTable dt = (DataTable)Session["dtCNRCoDe"];
        //    DataRow[] row = dt.Select(string.Format("CNRSegment='{0}' and CNRCoDe='{1}'", ddlCNRSegment.SelectedItem.Text, ddlCNRCoDe.SelectedItem.Text));
        //    if (row.Length > 0)
        //    {
        //        txtContractNo.Value = comm.GetContractNoRegulation(row[0]["CNRHead"].ToString(), row[0]["CNRFoot"].ToString());
        //    }
        //    else { txtContractNo.Value = ""; }
        //}
        //ChanageClick();
        QueryNew();
    }
    public void ChanageClick()
    {
        if (Session["ContractTable"] != null)
        {
            contracttable = Session["ContractTable"].ToString();
        }
        else
        {
            contracttable = "Nothing!";
        }
        //else { Response.Redirect(CommonModel.errorTimeOutUrl1); }
    }

    #region 公司部门、合同浏览组
    // CoDep
    protected void CoDepBind(string userCode)
    {
        ddlCoDep.DataSource = comm.getCoDepGroup(userCode);
        ddlCoDep.DataValueField = "CoDepCode";
        ddlCoDep.DataTextField = "CoDepName";
        ddlCoDep.DataBind();
        ddlCoDep.Items.Insert(0, new ListItem("请选择(Please Select)", "-1"));
    }
    // 绑定合同浏览组
    private void contractGroupBind(string userCode, int n)
    {
        if (!ddlCoDep.SelectedValue.Equals("-1"))
        {
            ddlcontractGroup.DataSource = comm.getContractGroup(ddlCoDep.SelectedValue.ToString());
            ddlcontractGroup.DataValueField = "CGCode";
            ddlcontractGroup.DataTextField = "CGName";
            ddlcontractGroup.DataBind();
            // 初始化绑定内容
            //model.contractGroup = ddlcontractGroup.SelectedValue;
            //model.ContractNoMain = "";
            //model.pageIndex = 0;
            //model.pageNextIndex = 1;
            //model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
            //lblPageIndex.Text = "1";
            //model.Condiction = "";
            //contractBind(model);
        }
        else { ddlcontractGroup.Items.Clear(); }
        ddlcontractGroup.Items.Insert(0, new ListItem("请选择(Select Please)", "-1"));
        contracttable = "Nothing！";
    }    
    #endregion
    #region 绑定合同信息
    public void contractBind(ContractModel model)
    {
        if (!string.IsNullOrEmpty(model.contractGroup))
        { contracttable = contractTableBuild(this, model).ToString(); }
        else
        {
            CommonMethod.regAlertMessage(this.updHead, "Nothing for you to View！", this);
            lblMessage.Text = "Nothing for you to View！";
        }
    }
    public string contractTableBuild(System.Web.UI.Page page, ContractModel model)
    {
        CommonMethod.IsTimeOutUserCodeAndCoCode(this, CommonModel.errorTimeOutUrl1);
        model.CoCode = Session["CoCode"].ToString();
        model.UserCode = Session["UserCode"].ToString();
        model.ContractPage = this;
        model.queryLevel = Convert.ToInt16(hidQueryFlag.Value.ToString());
        lblMessage.Text = "";

        DataTable[] dt = comm.ContractHeadBuid(model);
        StringBuilder table = new StringBuilder();
        if (dt.Length > 3 && dt[0].Rows.Count > 0 && dt[1].Rows.Count > 0 && dt[2].Rows.Count > 0)
        {
            model.columnUserRight = dt[2];
            model.listNamesDT = dt[3];
            if (model.queryLevel == 0)
            { model.Condiction = string.Format(" and C.ContractNoMain='{0}' and C.CoDepCode='{1}'", txtContractNo.Value.Trim(), model.contractCoDep); }
            else if (model.queryLevel == 1)
            {
                model.Condiction = string.Format(" and C.ContractNoMain like '%{0}%' and (C.CoDepCode='{1}' or len(C.CoDepCode)=0) ",
                    txtContractNo1.Value.ToString().Trim(), ddlCoDep.SelectedValue.ToString());
            }
            else if (model.queryLevel == 2)
            {
                string condiction = string.Empty;
                #region Condiction
                if (!string.IsNullOrEmpty(txtContractNo2.Text))
                {
                    condiction += string.Format(" and C.ContractNoMain like '%{0}%'", txtContractNo2.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtContractNoCustomer.Text))
                {
                    condiction += string.Format(" and C.ContractNoCust like '%{0}%'", txtContractNoCustomer.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtCustomerName.Text))//CUS
                {
                    condiction += string.Format(" and CUS.CustomerName like '%{0}%'", txtCustomerName.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtSaleName.Text))
                {
                    condiction += string.Format(" and SC.SalesName like '%{0}%'", txtSaleName.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtSoNo.Text))
                {
                    condiction += string.Format(" and TradingPlant.TradingSoNo like '%{0}%'", txtSoNo.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtPlantSoNo.Text))
                {
                    condiction += string.Format(" and TradingPlant.PlantSoNo like '%{0}%'", txtPlantSoNo.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtOHName.Text))
                {
                    condiction += string.Format(" and OHL.OHName like '%{0}%'", txtOHName.Text.Trim());
                }
                if (!string.IsNullOrEmpty(txtCEName.Text))
                {
                    condiction += string.Format(" and CRAE.CEName like '%{0}%'", txtCEName.Text.Trim());
                }
                #endregion
                model.Condiction = condiction + string.Format(" and (C.CoDepCode='{0}' or len(C.CoDepCode)=0) ", ddlCoDep.SelectedValue.ToString());
            }

            DataTable rowsDT = comm.ContractList(model, dt[1]);
            if (rowsDT != null && rowsDT.Rows.Count > 0)
            {
                table.Append(ContractBuildBLL.ContractBuild(model, dt, rowsDT));
            }
            else
            {
                string contractTemp = (model.queryLevel == 1 ? txtContractNo1.Value.ToString() : txtContractNo2.Text.ToString());
                //CommonMethod.regAlertMessage(updHead, comm.GetCoDepByContractNo(contractTemp), this);
                lblMessage.Text = comm.GetCoDepByContractNo(contractTemp);
            }
            SetPage(rowsDT, model);
        }
        else { table.Append("Can not get data!"); }
        Session["ContractTable"] = table.ToString();
        return table.ToString();
    }
    #endregion

    #region New Contract
    protected void cmdNew_Click(object sender, EventArgs e)
    {
        CommonMethod.IsTimeOutUserCodeAndCoCode(this, CommonModel.errorTimeOutUrl1);
        hidQueryFlag.Value = "0";
        lblMessage.Text = "";
        string cNO = string.Empty;
        if (!string.IsNullOrEmpty(txtContractNo.Value.Trim()))
        { cNO = txtContractNo.Value.Trim(); }
        else if (!ddlCoDep.SelectedValue.ToString().Equals("-1"))
        {
            #region 自动生成合同号
            if (Session["dtCNRCoDe"] != null)
            {
                DataTable dt = (DataTable)Session["dtCNRCoDe"];
                DataRow[] row = dt.Select(string.Format("CNRSegment='{0}' and CNRCoDe='{1}'", ddlCNRSegment.SelectedItem.Text, ddlCoDep.SelectedValue.ToString()));
                if (row.Length > 0)
                {
                    cNO = comm.GetContractNoRegulation(row[0]["CNRHead"].ToString(), row[0]["CNRFoot"].ToString());
                }
            }
            else if (Session["dtCNRCoDe"] == null)
            {
                cNO = comm.GetContractNoRegulation2(ddlCNRSegment.SelectedItem.Text, ddlCoDep.SelectedValue.ToString());
            }
            #endregion
            txtContractNo.Value = cNO;
        }

        if (cNO.Trim().Length > 0)
        {
            #region New Contract
            model.CoCode = Session["CoCode"].ToString();
            model.UserCode = Session["UserCode"].ToString();
            model.ContractNoMain = cNO;
            model.contractCoDep = ddlCoDep.SelectedValue.ToString();

            if (comm.AddContract(model) > 0)
            {
                CommonMethod.regAlertMessage(this.updHead, "Success！", this);
                //绑定内容
                model.contractGroup = ddlcontractGroup.SelectedValue;
                model.ContractNoMain = "";
                model.pageIndex = 0;
                model.pageNextIndex = 1;
                model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
                lblPageIndex.Text = "1";
                //model.Condiction = string.Format(" and C.ContractNoMain='{0}' and C.CoDepCode='{1}'", cNO, model.contractCoDep);
                contracttable = contractTableBuild(this, model).ToString();
            }
            #endregion
            else
            {
                CommonMethod.regAlertMessage(updHead, "Failed, It might have exitde！", this);
                lblMessage.Text = "Failed, It might have exitde！";
            }//ChanageClick();                
        }
        else
        {
            CommonMethod.regAlertMessage(updHead, "Can not Null！", this);
            lblMessage.Text = "Can not Null！";
        }//ChanageClick();
    }
    #endregion
    #region 按合同号，简单查询
    protected void cmdSearch_Click(object sender, EventArgs e)
    {
        //绑定内容
        hidQueryFlag.Value = "1";
        model.contractGroup = ddlcontractGroup.SelectedValue;
        model.ContractNoMain = txtContractNo1.Value.Trim();
        model.pageIndex = 0;
        model.pageNextIndex = 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = "1";
        model.queryLevel = 1;
        contracttable = contractTableBuild(this, model).ToString();
    }
    #endregion
    #region 高级查询
    protected void cmdQueryMore_Click(object sender, EventArgs e)
    {
        hidQueryFlag.Value = "2";
        model.contractGroup = ddlcontractGroup.SelectedValue;
        model.pageIndex = 0;
        model.pageNextIndex = 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = "1";

        model.queryLevel = 2;
        contractBind(model);
        lblMessage.Text = "";
    }
    #endregion
    #region 换页设置
    public void SetPage(DataTable dt, ContractModel model)
    {
        int toaltNum = (dt == null ? 0 : dt.Rows.Count);
        int pagesize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        this.lblTotal.Text = toaltNum.ToString();
        int pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        int pageCount = toaltNum / pagesize;

        if (pageCount * pagesize == toaltNum) { }
        else { pageCount = pageCount + 1; }

        txtNewPageIndex.Value = pageIndex.ToString();
        this.lblPageCount.Text = pageCount.ToString();

        if (pageIndex < pageCount)
        {
            if (pageIndex == 1)
            {
                lbtFirstPage.Enabled = false;
                lbtPreviousPage.Enabled = false;
                lbtNextPage.Enabled = true;
                lbtLastPage.Enabled = true;
            }
            else 
            {
                lbtFirstPage.Enabled = true;
                lbtPreviousPage.Enabled = true;
                lbtNextPage.Enabled = true;
                lbtLastPage.Enabled = true;
            }
        }
        else
        {
            if (pageIndex > 1)
            {
                lbtFirstPage.Enabled = true;
                lbtPreviousPage.Enabled = true;
                lbtNextPage.Enabled = false;
                lbtLastPage.Enabled = false;
                btnGo.Enabled = true;
            }
            else
            {
                lbtFirstPage.Enabled = false;
                lbtPreviousPage.Enabled = false;
                lbtNextPage.Enabled = false;
                lbtLastPage.Enabled = false;
                btnGo.Enabled = false;
            }
        }
    }
    #endregion

    #region 换页
    // 跳页
    protected void btnGo_Click(object sender, EventArgs e)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = Convert.ToInt16(txtNewPageIndex.Value.ToString());
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = model.pageNextIndex.ToString();
        //绑定内容
        if (!(model.pageIndex == model.pageNextIndex))
        {
            model.contractGroup = ddlcontractGroup.SelectedValue;
            contracttable = contractTableBuild(this, model).ToString();
        }
        else
        {
            //contracttable = Session["ContractTable"].ToString();
        }
    }
    //第一页
    protected void lbtFirstPage_Click(object sender, EventArgs e)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = model.pageNextIndex.ToString();
        //绑定内容
        model.contractGroup = ddlcontractGroup.SelectedValue;
        contracttable = contractTableBuild(this, model).ToString();
    }
    // 上一页
    protected void lbtPreviousPage_Click(object sender, EventArgs e)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = Convert.ToInt16(lblPageIndex.Text.ToString()) - 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = model.pageNextIndex.ToString();
        //绑定内容
        model.contractGroup = ddlcontractGroup.SelectedValue;
        contracttable = contractTableBuild(this, model).ToString();
    }
    // 下一页
    protected void lbtNextPage_Click(object sender, EventArgs e)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = Convert.ToInt16(lblPageIndex.Text.ToString()) + 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = model.pageNextIndex.ToString();
        //绑定内容
        model.contractGroup = ddlcontractGroup.SelectedValue;
        contracttable = contractTableBuild(this, model).ToString();

    }
    // 最后一页
    protected void lbtLastPage_Click(object sender, EventArgs e)
    {
        model.pageIndex = Convert.ToInt16(lblPageIndex.Text.ToString());
        model.pageNextIndex = Convert.ToInt16(lblPageCount.Text.ToString());
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = model.pageNextIndex.ToString();
        //绑定内容
        model.contractGroup = ddlcontractGroup.SelectedValue;
        contracttable = contractTableBuild(this, model).ToString();
    }
    #endregion

    #region PageSize Chanaged
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        //绑定内容
        model.contractGroup = ddlcontractGroup.SelectedValue;
        model.ContractNoMain = "";
        model.pageIndex = 0;
        model.pageNextIndex = 1;
        model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
        lblPageIndex.Text = "1";
        contracttable = contractTableBuild(this, model).ToString();
    }
    #endregion

    #region 更新数据
    protected void cmdContractUpdateFromDB_Click(object sender, EventArgs e)
    {
        if (Session["ContractNos"] != null)
        {
            CommonMethod.IsTimeOutUserCodeAndCoCode(this, CommonModel.errorTimeOutUrl1);
            model.CoCode = Session["CoCode"].ToString();
            model.UserCode = Session["UserCode"].ToString();
            model.contractNos = Session["ContractNos"].ToString();

            /***
            string condiction = string.Empty;
            if (!string.IsNullOrEmpty(txtDateFrom.Value) && !string.IsNullOrEmpty(txtDateTo.Value))
            {
                condiction += " and convert(datetime,AddDate) between convert(datetime,'"
                    + txtDateFrom.Value + "')  and  convert(datetime,'" + txtDateTo.Value + "') ";
            }
            else if (!string.IsNullOrEmpty(txtDateFrom.Value))
            {
                condiction += " and convert(datetime,AddDate)>=convert(datetime,'" + txtDateFrom.Value + "') ";
            }
            else if (!string.IsNullOrEmpty(txtDateTo.Value))
            {
                condiction += " and convert(datetime,AddDate)<=convert(datetime,'" + txtDateTo.Value + "') ";
            }
            DataTable ContractNoDt = comm.GetContractNoForUpdate(condiction);

            if (ContractNoDt != null && ContractNoDt.Rows.Count > 0)
            {
                model.contractNos = CommonMethod.StrMerge(ContractNoDt, "ContractNoMain");

                int n = chkDateUpdate.Items.Count;
                for (int i = 0; i < n; i++)
                {
                    if (chkDateUpdate.Items[i].Selected)
                    {
                        comm.ContractUpdate(model, Convert.ToInt16(chkDateUpdate.Items[i].Value));
                    }
                }
            }
            ***/

            int n = chkDateUpdate.Items.Count;
            for (int i = 0; i < n; i++)
            {
                if (chkDateUpdate.Items[i].Selected)
                {
                    comm.ContractUpdate(model, Convert.ToInt16(chkDateUpdate.Items[i].Value));
                }
            }

            //绑定内容
            model.contractGroup = ddlcontractGroup.SelectedValue;
            model.ContractNoMain = "";
            model.pageIndex = 0;
            model.pageNextIndex = 1;
            model.pageSize = Convert.ToInt16(ddlPageSize.SelectedItem.Text.ToString());
            lblPageIndex.Text = "1";
            model.Condiction = " and C.ContractNoMain in (" + model.contractNos + "'')";
            contracttable = contractTableBuild(this, model);
        }
    }
    #endregion

    #region 高级查询初始化绑定
    protected void ddlOHName_TextChanged(object sender, EventArgs e)
    {
        if (!ddlOHName.SelectedValue.Equals("-1"))
        { txtOHName.Text = ddlOHName.SelectedItem.Text; }
        else { txtOHName.Text = ""; }
        CommonMethod.regAlertMessageScript(updcontract, "showHidden('ddlOHName','ddlOHName', 'txtOHName','txtOHName')", this);
        CommonMethod.regAlertMessageScript(updcontract, "show('queryForMore','block','gray');", this);
    }
    protected void ddlCEName_TextChanged(object sender, EventArgs e)
    {
        if (!ddlCEName.SelectedValue.Equals("-1"))
        { txtCEName.Text = ddlCEName.SelectedItem.Text; }
        else { txtCEName.Text = ""; }
        CommonMethod.regAlertMessageScript(updcontract, "showHidden('ddlCEName','ddlCEName', 'txtCEName','txtCEName')", this);
        CommonMethod.regAlertMessageScript(updcontract, "show('queryForMore','block','gray');", this);
    }
    protected void ddlSaleName_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!ddlSaleName.SelectedValue.Equals("-1"))
        { txtSaleName.Text = ddlSaleName.SelectedItem.Text; }
        else { txtSaleName.Text = ""; }
        CommonMethod.regAlertMessageScript(updcontract, "showHidden('ddlSaleName','ddlSaleName', 'txtSaleName','txtSaleName')", this);
        CommonMethod.regAlertMessageScript(updcontract, "show('queryForMore','block','gray');", this);
    }
    public void MoreQueryDdlBind()
    {
        DataTable[] dt = comm.GetddlForadAancedQuery();
        if (dt != null)
        {
            //ListItem item = new ListItem("请选择(Select Please)", "-1");
            //ddlCEName.Items.Add(item);
            //ddlOHName.Items.Add(item);

            //DataRow[] ohRow = dt[0].Select("ListNameType='OHName'");
            //foreach (DataRow row in ohRow)
            //{
            //    ddlOHName.Items.Add(new ListItem(row["ListName"].ToString(), row["ListName"].ToString()));
            //}

            //DataRow[] ceRow = dt[0].Select("ListNameType='CEName'");
            //foreach (DataRow row in ceRow)
            //{
            //    ddlCEName.Items.Add(new ListItem(row["ListName"].ToString(), row["ListName"].ToString()));
            //}
            if (dt[0] != null)
            {
                ddlCEName.DataSource = dt[0];
                ddlCEName.DataValueField = "CEName";
                ddlCEName.DataTextField = "CEName";
                ddlCEName.DataBind();
                ddlCEName.Items.Insert(0, new ListItem("请选择(Select Please)", "-1"));
            }
            if (dt[1] != null)
            {
                ddlOHName.DataSource = dt[1];
                ddlOHName.DataValueField = "OHName";
                ddlOHName.DataTextField = "OHName";
                ddlOHName.DataBind();
                ddlOHName.Items.Insert(0, new ListItem("请选择(Select Please)", "-1"));
            }
            if (dt[2] != null)
            {
                ddlSaleName.DataSource = dt[2];
                ddlSaleName.DataValueField = "SalesName";
                ddlSaleName.DataTextField = "SalesName";
                ddlSaleName.DataBind();
                ddlSaleName.Items.Insert(0, new ListItem("请选择(Select Please)", "-1"));
            }
        }
    }
    #endregion
}